package com.jh3502.vivo.function.me;

import android.os.Bundle;
import android.widget.TextView;

import com.jh3502.vivo.R;
import com.jh3502.vivo.base.BaseFragment;
import com.jh3502.vivo.base.BasePresenter;
import com.jh3502.vivo.function.account.AccountActivity;
import com.jh3502.vivo.function.login.LoginActivity;
import com.jh3502.vivo.function.main.TitleBean;
import com.jh3502.vivo.function.passchange.PassChangeActivity;
import com.jh3502.vivo.utils.ActivityTracker;
import com.jh3502.vivo.utils.SpHelper;
import com.jh3502.vivo.utils.Utils;
import com.jh3502.vivo.view.MyRecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * author:harisucici on 2018/11/7 10:19
 * email:harisucici@gmail.com
 * name:
 * todo:
 */
public class MeFragment extends BaseFragment {
    @BindView(R.id.me_menu)
    MyRecyclerView meMenu;
    @BindView(R.id.include_user_detail_name)
    TextView includeUserDetailName;
    @BindView(R.id.include_user_detail_com)
    TextView includeUserDetailCom;
    Unbinder unbinder;
    private String[] title = {"个人信息", "修改密码", "银行账户"};
    private int[] images = {R.drawable.ic_personalinformation, R.drawable.ic_changepassword, R.drawable.ic_bankaccount};
    private List<TitleBean> titles = new ArrayList<>(2);

    @Override
    public BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected int setViewId() {
        return R.layout.fragment_me;
    }


    @Override
    protected void initView() {
        initMenu();
        MeAdapter meAdapter = new MeAdapter(mContext, titles);
        meMenu.setAdapter(meAdapter);
        meAdapter.setOnItemClickListener(s -> {
            if (s == 0) {
                Utils.getInstance().startActivity(mActivity, MeActivity.class);
            } else if (s == 1) {
                Utils.getInstance().startActivity(mActivity, PassChangeActivity.class);
            } else if (s == 2) {
                Utils.getInstance().startActivity(mActivity, AccountActivity.class);
            }

        });

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void doOnDestroy() {

    }

    @Override
    protected void doOnResume() {
        includeUserDetailName.setText(SpHelper.getInstance().getUserName());
        includeUserDetailCom.setText(SpHelper.getInstance().getDeptName());
    }

    @Override
    protected void doOnVisible() {
    }

    @Override
    protected void doOnInvisible() {

    }

    @Override
    protected void doOnSaveInstanceState(Bundle savedInstanceState) {

    }

    @Override
    public void responseError(int code, String msg) {

    }

    @Override
    public void requestFailure(Throwable t) {

    }

    private void initMenu() {
        for (int i = 0; i < title.length; i++) {
            TitleBean titleBean = new TitleBean();
            titleBean.setTitle(title[i]);
            titleBean.setImageId(images[i]);
            titles.add(titleBean);
        }


    }


    @OnClick(R.id.me_help)
    public void onMeHelpClicked() {
        showShortToast("help");
    }

    @OnClick(R.id.me_exit)
    public void onMeExitClicked() {
        SpHelper.getInstance().clearAll();
        ActivityTracker.getInstance().finishAll();
        Utils.getInstance().startActivity(mActivity, LoginActivity.class);
    }


}
